import request from '@/utils/http'

export interface ImportRequest {
  app_name: string
  table_schema: string
  table_name: string
}

/**
 * 导入业务与模型元数据
 * 后端接口：POST /api/v1/code-generator/import
 */
export function importCode(req: ImportRequest) {
  return request.post<void>({
    url: '/code-generator/import',
    data: req,
    showSuccessMessage: true
  })
}

/**
 * 生成代码到磁盘
 * 后端接口：POST /api/v1/code-generator/generate/{gen_business_id}?overwrite=false
 */
export function generateCode(genBusinessId: number, overwrite = false) {
  return request.post<string[]>({
    url: `/code-generator/generate/${genBusinessId}`,
    // 确保 overwrite 作为查询参数传递
    params: { overwrite },
    // 传空体以避免封装层将 params 移到 data
    data: {},
    showSuccessMessage: true
  })
}

